import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Redirect")
public class RedirectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //当用户访问这个路径的时候，自动进行重定向到搜狗的主页
        /* resp.setStatus(302);
        resp.setHeader("location","https://www.sogou.com"); */
        //也可以把上述两行代码合并成一行
        resp.sendRedirect("https://www.sogou.com");
    }
}
